# 每个格子两种情况，一共2的100次最多，要剪枝
def check(x, y):
    num = int(mp[x][y])
    for d in [(0, 0), (1, 0), (0, 1), (1, 1), (-1, 0), (0, -1), (-1, -1), (1, -1), (-1, 1)]:
        nx = x + d[0]
        ny = y + d[1]
        if 0 <= nx < n and 0 <= ny < m:
            num -= ans[nx][ny]
    if num != 0:
        return False
    else:
        return True

def dfs(x, y):
    global flag
    # 结果输出部分
    if flag==1:
      return
    # 当成功处理完第n - 1行最后一列（坐标[n - 1, m - 1]）后
    if x == n and y == 0:
        for i in range(m):  # 最后一行验证
            if mp[x - 1][i] != '_':
                if not check(x - 1, i):
                    return
        if mp[x - 2][m - 2] != '_':  # 倒数第二行倒数第二列
            if not check(x - 2, m - 2):
                return
        if mp[x - 2][m - 1] != '_':  # 倒数第二行最后一列
            if not check(x - 2, m - 1):
                return
        for a in ans:
            for i in a:
                print(i, end='')
            print()
        flag = 1
        return

    # 剪枝部分
    # 剪枝条件1：当处理到第x行第y列时（y≥2）
    if x >= 1 and y >= 2:
        # 检查前一行左数第3列（坐标[x-1, y-2]）
        if mp[x - 1][y - 2] != '_':
            if not check(x - 1, y - 2):
                return
    # 剪枝条件2：当换行到第x行首列时（x≥2）
    if x >= 2 and y == 0:
        # 检查前前一行倒数第2列（坐标[x-2, m-2]）
        if mp[x - 2][m - 2] != '_':
            if not check(x - 2, m - 2):
                return
        # 检查前前一行倒数第1列（坐标[x-2, m-1]）
        if mp[x - 2][m - 1] != '_':
            if not check(x - 2, m - 1):
                return

    # 生成部分
    # 横向填充（同一行内向右移动）
    if y != m - 1:
        ans[x][y] = 0    # 尝试无雷
        dfs(x, y + 1)    # 递归右侧相邻格子
        ans[x][y] = 1    # 回溯后尝试有雷
        dfs(x, y + 1)    # 再次递归右侧格子

    # 纵向换行（到达行尾后跳转到下一行行首）
    if y == m - 1 and x <= n - 1:
        ans[x][y] = 0    # 行末尝试无雷
        dfs(x + 1, 0)    # 换行到下一行开头
        ans[x][y] = 1    # 回溯后尝试有雷
        dfs(x + 1, 0)    # 再次换行递归


n, m = map(int, input().split())
mp = []
for i in range(n):
    mp.append(input())
ans = [[0] * m for _ in range(n)]
flag = 0
dfs(0, 0)


# def check(x, y):
#     if mp[x][y] != '_':
#         num = int(mp[x][y])
#         dir = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 0), (0, 1), (1, -1), (1, 0), (1, 1)]
#         for i, j in dir:
#             nx, ny = x + i, y + j
#             if 0 <= nx < n and 0 <= ny < m:
#                 num -= ans[nx][ny]
#         if num == 0:
#             return True
#         else:
#             return False
#     else:
#         return True
#
#
# def dfs(x, y):
#     global flag
#     # 结果输出部分
#     if flag == 1:
#         return
#     if x == n and y == 0:
#         for i in range(m):
#             if not check(n - 1, i):
#                 return
#         if not check(n - 2, m - 2):
#             return
#         if not check(n - 2, m - 1):
#             return
#         for a in ans:
#             for i in a:
#                 print(i, end='')
#             print()
#         flag = 1
#         return
#
#     # 剪枝部分
#     if x >= 1 and y >= 2:
#         if not check(x - 1, y - 2):
#             return
#     if x >= 2 and y == 0:
#         if not check(x - 2, m - 1):
#             return
#         if not check(x - 2, m - 2):
#             return
#
#     # 填充部分
#     if y != m - 1:
#         ans[x][y] = 0
#         dfs(x, y + 1)
#         ans[x][y] = 1
#         dfs(x, y + 1)
#     if y == m - 1 and x <= n - 1:
#         ans[x][y] = 0
#         dfs(x + 1, 0)
#         ans[x][y] = 1
#         dfs(x + 1, 0)
#
#
# n, m = map(int, input().split())
# mp = [list(input()) for _ in range(n)]
# ans = [[0] * m for _ in range(n)]
# flag = 0
# dfs(0, 0)